package com.pignest.hotel.system.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class SetCharacterEncodingFilter implements Filter {

	public void destroy() {
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
//		showParameters((HttpServletRequest)request);
		request.getParameter("hello");
		request.setCharacterEncoding("GBK");
//		showParameters((HttpServletRequest)request);
//		request.setCharacterEncoding("UTF-8");
//		showParameters((HttpServletRequest)request);
//		System.out.println();
		chain.doFilter(request, response);
	}

	public void init(FilterConfig filterConfig) throws ServletException {
	}

//	@SuppressWarnings("unchecked")
//	private void showParameters(HttpServletRequest request) throws UnsupportedEncodingException {
//		Map<String, String[]> params = request.getParameterMap();
//		for (Map.Entry<String, String[]> e : params.entrySet()) {
//			String key = e.getKey();
//			String[] value = e.getValue();
//			if (StringUtils.isNotEmpty(value[0]))
//				System.out.println(key + "=" + Utils.e(value[0]));
//		}
//	}
	
}
